import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-03-29
 * Time: 15:07
 */
public class Main {
    public static void main(String[] args) {
        // 初始化学生数组
        Student[] students = {
                new Student("张三", 20, 88.5),
                new Student("李四", 19, 92.0),
                new Student("王五", 22, 85.0),
                new Student("赵六", 25, 96.5)
        };

        // 打印原始数据
        System.out.println("========== 原始数据 ==========");
        printStudents(students);

        // 使用不同比较器进行排序演示
        System.out.println("\n====== 按年龄升序排列 ======");
        Arrays.sort(students);//创建比较器对象 new AgeComparator()
        //Arrays.sort()	通用排序方法，通过传入不同的Comparator实现不同排序规则
        //允许通过接口类型（Comparator）操作不同的比较器实现类 --多态
        printStudents(students);

        System.out.println("\n===== 按成绩降序排列 =====");
        Arrays.sort(students, new ScoreComparator());
        printStudents(students);

        System.out.println("\n===== 按姓名拼音排序 =====");
        Arrays.sort(students, new NameComparator());
        printStudents(students);
    }

    // 辅助方法：打印学生数组
    private static void printStudents(Student[] students) {
        for (Student s : students) {
            System.out.println(s);// 自动调用toString()方法
        }
    }
}
/*
========== 原始数据 ==========
        [张三|20|88.5]
        [李四|19|92.0]
        [王五|22|85.0]
        [赵六|25|96.5]

        ====== 按年龄升序排列 ======
        [李四|19|92.0]
        [张三|20|88.5]
        [王五|22|85.0]
        [赵六|25|96.5]

        ===== 按成绩降序排列 =====
        [赵六|25|96.5]
        [李四|19|92.0]
        [张三|20|88.5]
        [王五|22|85.0]

        ===== 按姓名拼音排序 =====
        [张三|20|88.5]
        [李四|19|92.0]
        [王五|22|85.0]
        [赵六|25|96.5]

*/
